package com.stu.entity.permission;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.stu.entity.base.BaseEntity;

@Entity
@Table(name = "PERMISSION_AUTH")
public class PermissionAuth extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String cname;// 名称
	private String url; // 请求路径
	private String description; // 描述
	private String isMenu; // 是否是菜单
	private PermissionMenu menu; // 菜单

	private List<PermissionRole> roles = new ArrayList<PermissionRole>();

	public PermissionAuth() {

	}
	
	public PermissionAuth(String uuid) {
		super(uuid);
	}

	@Column(name = "cname", length = 50)
	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	@Column(name = "url", length = 255)
	public String getUrl() {
//		if (Constant.YES_OR_NO_Y.equals(isMenu)) {
//			if (menu != null)
//				return menu.getUrl();
//			else
//				return "";
//		}
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "description", length = 255)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "ismenu", length = 4)
	public String getIsMenu() {
//		if (isMenu == null)
//			return Constant.YES_OR_NO_N;
		return isMenu;
	}

	public void setIsMenu(String isMenu) {
		this.isMenu = isMenu;
	}

	@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinColumn(name = "menu")
	public PermissionMenu getMenu() {
		return menu;
	}

	public void setMenu(PermissionMenu menu) {
		this.menu = menu;
	}

	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name = "PERMISSION_ROLE_AUTH", joinColumns = { @JoinColumn(name = "auth_id", referencedColumnName = "uuid") }, inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "uuid") })
	public List<PermissionRole> getRoles() {
		return roles;
	}

	public void setRoles(List<PermissionRole> roles) {
		this.roles = roles;
	}


}
